package com.zhuo.project.order.service.task;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.zhuo.project.order.domain.ZzTask;
import com.zhuo.project.order.service.IZzDiagnoseReturnService;
import com.zhuo.project.order.service.IZzDiagnoseSendService;
import com.zhuo.project.order.service.IZzTaskService;

/**
 * @project name: ruoyi
 * @author: fuhao <fuhao@kuaishou.com>
 * @team 快手-商业化-直营电商
 * @Package com.zhuo.project.order.service.task
 * @create: 2020-04-11 12:06
 * @description:
 **/
@Component("k3Task")
public class OrderDeliveryTask {
    private static Logger logger = LoggerFactory.getLogger(OrderDeliveryTask.class);

    @Autowired
    private IZzTaskService iZzTaskService;

    @Autowired
    private IZzDiagnoseSendService iZzDiagnoseSendService;

    @Autowired
    private IZzDiagnoseReturnService iZzDiagnoseReturnService;

    public void deliveryOrder()
    {
        List<ZzTask> zzTaskList =  iZzTaskService.selectZzTaskListByType(40);
        for (ZzTask zzTask: zzTaskList) {
            logger.info("开始推送给k3 = {}",zzTask.getRefId());
            try {
                iZzDiagnoseSendService.sendDelivery2K3(zzTask);
            }catch (Exception ex) {
                logger.error(zzTask.getRefId() + ex.getMessage());
            }
            logger.info("结束推送给k3 = {}",zzTask.getRefId());
        }
        logger.info("执行发药单推送结束");
    }

    public void returnOrder()
    {
        List<ZzTask> zzTaskList =  iZzTaskService.selectZzTaskListByType(50);
        for (ZzTask zzTask:zzTaskList) {
            logger.info("开始推送退药单给k3 = {}",zzTask.getRefId());
            try {
           iZzDiagnoseReturnService.sendReturnOrder2K3(zzTask);
            }catch (Exception ex) {
                logger.error("推送退药单异常:单号{}, 异常信息:{} " ,zzTask.getRefId() , ex.getMessage());
            }
            logger.info("结束推送退药单给k3 = {}",zzTask.getRefId());
        }
        logger.info("执行退药单推送结束");
    }
}
